Micron Document
NexusPi Git Node


Displaying Raw • Download

lib/microReticulum/src/Cryptography/CBC.cpp copilot/add-rtnode-configuration-options (9529fa8a) Text, 4.59 KB

T8b949e/*
* Copyright (C) 2015 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

Tff7b72#Tff7b72include T8b949e"CBC.h"
Tff7b72#Tff7b72include T8b949e<Crypto.h>
Tff7b72#Tff7b72include T8b949e<string.h>

T8b949e/**
* \class CBCCommon CBC.h <CBC.h>
* \brief Concrete base class to assist with implementing CBC for
* 128-bit block ciphers.
*
* Reference: http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
*
* \sa CBC
*/

T8b949e/**
* \brief Constructs a new cipher in CBC mode.
*
* This constructor should be followed by a call to setBlockCipher().
*/
Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3CBCCommonTb4b4b4(Tb4b4b4)
Tff7b72: Te6edf3blockCipherTb4b4b4(T79c0ff0Tb4b4b4)
Tb4b4b4, Te6edf3posnTb4b4b4(T79c0ff16Tb4b4b4)
Tb4b4b4{
Tb4b4b4}

T8b949e/**
* \brief Destroys this cipher object after clearing sensitive information.
*/
Te6edf3CBCCommonTff7b72:Tff7b72:Tff7b72~Te6edf3CBCCommonTb4b4b4(Tb4b4b4)
Tb4b4b4{
Te6edf3cleanTb4b4b4(Te6edf3ivTb4b4b4)Tb4b4b4;
Te6edf3cleanTb4b4b4(Te6edf3tempTb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657size_t Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3keySizeTb4b4b4(Tb4b4b4) Tff7b72const
Tb4b4b4{
Tff7b72return Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3keySizeTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657size_t Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3ivSizeTb4b4b4(Tb4b4b4) Tff7b72const
Tb4b4b4{
Tff7b72return T79c0ff16Tb4b4b4;
Tb4b4b4}

Tffa657bool Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3setKeyTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3keyTb4b4b4, Tffa657size_t Te6edf3lenTb4b4b4)
Tb4b4b4{
T8b949e// Verify the cipher's block size, just in case.
Tff7b72if Tb4b4b4(Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3blockSizeTb4b4b4(Tb4b4b4) Tff7b72!Tff7b72= T79c0ff16Tb4b4b4)
Tff7b72return Tffa657falseTb4b4b4;

T8b949e// Set the key on the underlying block cipher.
Tff7b72return Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3setKeyTb4b4b4(Te6edf3keyTb4b4b4, Te6edf3lenTb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657bool Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3setIVTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3ivTb4b4b4, Tffa657size_t Te6edf3lenTb4b4b4)
Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3len Tff7b72!Tff7b72= T79c0ff16Tb4b4b4)
Tff7b72return Tffa657falseTb4b4b4;
Te6edf3memcpyTb4b4b4(Tff7b72thisTff7b72-Tff7b72>Te6edf3ivTb4b4b4, Te6edf3ivTb4b4b4, T79c0ff16Tb4b4b4)Tb4b4b4;
Te6edf3posn Tff7b72= T79c0ff16Tb4b4b4;
Tff7b72return Tffa657trueTb4b4b4;
Tb4b4b4}

Tffa657void Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3encryptTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3outputTb4b4b4, Tff7b72const Tffa657uint8_tTff7b72* Te6edf3inputTb4b4b4, Tffa657size_t Te6edf3lenTb4b4b4)
Tb4b4b4{
Tffa657uint8_t Te6edf3posnTb4b4b4;
Tff7b72while Tb4b4b4(Te6edf3len Tff7b72>Tff7b72= T79c0ff16Tb4b4b4) Tb4b4b4{
Tff7b72for Tb4b4b4(Te6edf3posn Tff7b72= T79c0ff0Tb4b4b4; Te6edf3posn Tff7b72< T79c0ff16Tb4b4b4; Tff7b72+Tff7b72+Te6edf3posnTb4b4b4)
Te6edf3ivTb4b4b4[Te6edf3posnTb4b4b4] Tff7b72^Tff7b72= Tff7b72*Te6edf3inputTff7b72+Tff7b72+Tb4b4b4;
Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3encryptBlockTb4b4b4(Te6edf3ivTb4b4b4, Te6edf3ivTb4b4b4)Tb4b4b4;
Tff7b72for Tb4b4b4(Te6edf3posn Tff7b72= T79c0ff0Tb4b4b4; Te6edf3posn Tff7b72< T79c0ff16Tb4b4b4; Tff7b72+Tff7b72+Te6edf3posnTb4b4b4)
Tff7b72*Te6edf3outputTff7b72+Tff7b72+ Tff7b72= Te6edf3ivTb4b4b4[Te6edf3posnTb4b4b4]Tb4b4b4;
Te6edf3len Tff7b72-Tff7b72= T79c0ff16Tb4b4b4;
Tb4b4b4}
Tb4b4b4}

Tffa657void Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3decryptTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3outputTb4b4b4, Tff7b72const Tffa657uint8_tTff7b72* Te6edf3inputTb4b4b4, Tffa657size_t Te6edf3lenTb4b4b4)
Tb4b4b4{
Tffa657uint8_t Te6edf3posnTb4b4b4;
Tff7b72while Tb4b4b4(Te6edf3len Tff7b72>Tff7b72= T79c0ff16Tb4b4b4) Tb4b4b4{
Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3decryptBlockTb4b4b4(Te6edf3tempTb4b4b4, Te6edf3inputTb4b4b4)Tb4b4b4;
Tff7b72for Tb4b4b4(Te6edf3posn Tff7b72= T79c0ff0Tb4b4b4; Te6edf3posn Tff7b72< T79c0ff16Tb4b4b4; Tff7b72+Tff7b72+Te6edf3posnTb4b4b4) Tb4b4b4{
Tffa657uint8_t Te6edf3in Tff7b72= Tff7b72*Te6edf3inputTff7b72+Tff7b72+Tb4b4b4;
Tff7b72*Te6edf3outputTff7b72+Tff7b72+ Tff7b72= Te6edf3tempTb4b4b4[Te6edf3posnTb4b4b4] Tff7b72^ Te6edf3ivTb4b4b4[Te6edf3posnTb4b4b4]Tb4b4b4;
Te6edf3ivTb4b4b4[Te6edf3posnTb4b4b4] Tff7b72= Te6edf3inTb4b4b4;
Tb4b4b4}
Te6edf3len Tff7b72-Tff7b72= T79c0ff16Tb4b4b4;
Tb4b4b4}
Tb4b4b4}

Tffa657void Te6edf3CBCCommonTff7b72:Tff7b72:Te6edf3clearTb4b4b4(Tb4b4b4)
Tb4b4b4{
Te6edf3blockCipherTff7b72-Tff7b72>Te6edf3clearTb4b4b4(Tb4b4b4)Tb4b4b4;
Te6edf3cleanTb4b4b4(Te6edf3ivTb4b4b4)Tb4b4b4;
Te6edf3cleanTb4b4b4(Te6edf3tempTb4b4b4)Tb4b4b4;
Te6edf3posn Tff7b72= T79c0ff16Tb4b4b4;
Tb4b4b4}

T8b949e/**
* \fn void CBCCommon::setBlockCipher(BlockCipher *cipher)
* \brief Sets the block cipher to use for this CBC object.
*
* \param cipher The block cipher to use to implement CBC mode,
* which must have a block size of 16 bytes (128 bits).
*/

T8b949e/**
* \class CBC CBC.h <CBC.h>
* \brief Implementation of the Cipher Block Chaining (CBC) mode for
* 128-bit block ciphers.
*
* The template parameter T must be a concrete subclass of BlockCipher
* indicating the specific block cipher to use. T must have a block size
* of 16 bytes (128 bits).
*
* For example, the following creates a CBC object using AES192 as the
* underlying cipher:
*
* \code
* CBC<AES192> cbc;
* cbc.setKey(key, 24);
* cbc.setIV(iv, 16);
* cbc.encrypt(output, input, len);
* \endcode
*
* Decryption is similar:
*
* \code
* CBC<AES192> cbc;
* cbc.setKey(key, 24);
* cbc.setIV(iv, 16);
* cbc.decrypt(output, input, len);
* \endcode
*
* The size of the ciphertext will always be the same as the size of
* the plaintext. Also, the length of the plaintext/ciphertext must be a
* multiple of 16. Extra bytes are ignored and not encrypted. The caller
* is responsible for padding the underlying data to a multiple of 16
* using an appropriate padding scheme for the application.
*
* Reference: http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
*
* \sa CTR, CFB, OFB
*/

T8b949e/**
* \fn CBC::CBC()
* \brief Constructs a new CBC object for the block cipher T.
*/

Served by rngit 1.4.2 - Generated in 0.02s